package com.mall.untils;

import com.cloopen.rest.sdk.CCPRestSmsSDK;

import java.util.HashMap;
import java.util.Set;

/**
 * 发短信接口
 * <p/>
 * Created by konglinghui on 15/5/4.
 */
public class SMSUtil {

    public static void main(String[] args) {

        String content = "亲爱的园长您好，我是艾迪儿微信招生平台的李老师，欢迎您加入艾迪儿大家庭，由于电话无法与您取得联系，所以短信告知，幼儿园招生季即将来临，我们可以通过微信来为园所做线上宣传，挖掘生源，扩大招生！时间紧迫，请您尽快联系我们！联系电话:13381064585，13381064592";

        String phonesStr = "15186218437,13398587333,18798472812,13887436808,13887182053,13518580308,13595363505,18785879207,13040312288,15077592958,13471543541,15678668158,18643686880,13504363056,13948201420,13624361234,18677507790,18629172880,13807973509,15091173977,13660486066,13363969880,18392748928,15592654998,18502983335,15191963802,15009173452,13571738697,15229760906,13889132283,15754104476,18342378688,13897821722,18907970670,13479796193,13755810313,15279703999,15907976126,13907070304,15970748950,18979725113,13576759616,13576668639,13766368100,13177761261,18770498282,15979706965,13097071486,18970726206,15870748851,13879781071,18907970627,13870766755,13237672637,15387862539,13807973509,15070169802,15270760001,13697013363,18970706869,15860220588,15985890320,13606990357,13709302867,13779914000,13605022974,13774673252,13515962695,18539665657,15346509355,13503965159,13722858988,13517687694,13842702871,15642720135,15841712463,13898741358,13322252012,15878125827,159944554008,13457023636,13978568383,18275999787,17707742261,13878716286,13842516257,13464771300,15841775885,15604273258,18841750051,13768963219,13457023430,13878540399,15277605752,13481573490,13877540193,15977889929,13877555871,13877914724,13513985804,13703802135,18639685986,13723063028,15236386762,15286875918,15839626187,13223857001,13603806809,13461886057,15039611121,15855056512,15212022869,15255087792,18602535755,13956715369,15940550170,13700109254,13998122368,15566445359,13940574496,13324004038,13898711399,15124116821,13840384478,13904918448,15841441899,15804287889,13889299603,18640396278,13898831425,18640186250,18704107401,13008248770,13130297367,13842337160,13604225814,13022488896,13082416168,13889240346,13898151322,15524072628,13604000789,13478847110,15893933845,13956793122,13598909818,13938385372,13513993689,15539629096,15890846685,13783254178,13839908794,13183387018,18339603077,18137567179,15638393199,15836689602,13839660562,13603421456,18137565861,13838639190,18778108110,15007779903,13877228695,15278829028,18955231760,13879775570,13931924348,15097925497,18394034571,15569605179,18919822536,18693790824,13884001248,13830115791,15604273258,13842702871,13873003802,18390143392,13054089320,13574743798,18373010680,13974037655,13942516257,15039699569,13223969318,15978837379,15836778331,13272433407,15059778092,15959569955,13975037520,13975022529,15197138766,13574743798,13788833068,15159416848,13509566115,13489567470,13630760591,13054081568,15806610488,18973057577,15503506400,13103501351,13935035649,18235086403,13872265402,13797430382,13317229178,15927863872,18785864873,15186246961,13985374230,13408720756,18768780080,13808761983,13324950926,15987942828,13779914000,13840681099,13367655668,15077544531,15907858730,18978771748,13977591377,18278500703,15977546478,13878541858,15807898200,15077595117,15278357776,15944615077,18343603722,18179643333,15844619949,13258866393,13321572227,13998997657,18242148595,13897858743,13236891688,18949481178,15227602483,15731999959,15230015238,13343000956,18370765026,13786085273,15296103101,13558288530,13769217961,18977120247,15932281161,15131303460,13865507683,13870749439,13381064585";

        String[] phones = phonesStr.split(",");
        for (String phone : phones) {
            HttpRequest.sendPost("http://www.smswst.com/api/httpapi.aspx", "action=send&account=klh0318&password=888888&mobile=" + phone + "&content=" + content + "&AddSign=Y");
        }
    }

    public void sendCode(String phone, String code) {

        HashMap<String, Object> result = null;

        //初始化SDK
        CCPRestSmsSDK restAPI = new CCPRestSmsSDK();

        //******************************注释*********************************************
        //*初始化服务器地址和端口                                                       *
        //*沙盒环境（用于应用开发调试）：restAPI.init("sandboxapp.cloopen.com", "8883");*
        //*生产环境（用户应用上线使用）：restAPI.init("app.cloopen.com", "8883");       *
        //*******************************************************************************
        restAPI.init("sandboxapp.cloopen.com", "85103");

        //******************************注释*********************************************
        //*初始化主帐号和主帐号令牌,对应官网开发者主账号下的ACCOUNT SID和AUTH TOKEN     *
        //*ACOUNT SID和AUTH TOKEN在登陆官网后，在“应用-管理控制台”中查看开发者主账号获取*
        //*参数顺序：第一个参数是ACOUNT SID，第二个参数是AUTH TOKEN。                   *
        //*******************************************************************************
        restAPI.setAccount("8a48b5514dd25566014dd60b3c3901c7", "e82f5bbef9eb48f3b6a0584aea1d6341");


        //******************************注释*********************************************
        //*初始化应用ID                                                                 *
        //*测试开发可使用“测试Demo”的APP ID，正式上线需要使用自己创建的应用的App ID     *
        //*应用ID的获取：登陆官网，在“应用-应用列表”，点击应用名称，看应用详情获取APP ID*
        //*******************************************************************************
        restAPI.setAppId("8a48b5515388ec150153a28c62ac27c8");


        //******************************注释****************************************************************
        //*调用发送模板短信的接口发送短信                                                                  *
        //*参数顺序说明：                                                                                  *
        //*第一个参数:是要发送的手机号码，可以用逗号分隔，一次最多支持100个手机号                          *
        //*第二个参数:是模板ID，在平台上创建的短信模板的ID值；测试的时候可以使用系统的默认模板，id为1。    *
        //*系统默认模板的内容为“【云通讯】您使用的是云通讯短信模板，您的验证码是{1}，请于{2}分钟内正确输入”*
        //*第三个参数是要替换的内容数组。																														       *
        //**************************************************************************************************

        //**************************************举例说明***********************************************************************
        //*假设您用测试Demo的APP ID，则需使用默认模板ID 1，发送手机号是13800000000，传入参数为6532和5，则调用方式为           *
        //*result = restAPI.sendTemplateSMS("13800000000","1" ,new String[]{"6532","5"});																		  *
        //*则13800000000手机号收到的短信内容是：【云通讯】您使用的是云通讯短信模板，您的验证码是6532，请于5分钟内正确输入     *
        //*********************************************************************************************************************
        result = restAPI.sendTemplateSMS(phone, "75469", new String[]{code});

        System.out.println("SDKTestGetSubAccounts result=" + result);
        if ("000000".equals(result.get("statusCode"))) {
            //正常返回输出data包体信息（map）
            HashMap<String, Object> data = (HashMap<String, Object>) result.get("data");
            Set<String> keySet = data.keySet();
            for (String key : keySet) {
                Object object = data.get(key);
                System.out.println(key + " = " + object);
            }
        } else {
            //异常返回输出错误码和错误信息
            System.out.println("错误码=" + result.get("statusCode") + " 错误信息= " + result.get("statusMsg"));
        }
    }
}
